home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 January: Mac OS SDK / Dev.CD Jan 99 SDK1.toast / Development Kits / Installer SDK 1.2 / Upgrader 1.2.1 & Engines / Upgrader 1.2.1 / Plug-in Examples / SAM Virus Checker Plug-in / Editor Sources / CSAMLauncherEditorWindow.cp next >
Encoding:
Text File  |  1998-08-25  |  8.0 KB  |  271 lines  |  [TEXT/CWIE]

  1.  
  2. #include "CTextEditorWindow.h"
  3. #include "CFileRefEditorWindow.h"
  4. #include "CSAMLauncherEditorWindow.h"
  5. #include "EditorUtilities.h"
  6.  
  7. // Dialog panes
  8. const ResType     kPanelTitleET                     = 'ptsE';
  9. const ResType     kFirstHelpPicET                 = 'pihE';
  10. const ResType     kEditMainTextB                     = 'emtB';
  11. const ResType     kEditHelpTextB                     = 'ethB';
  12. const ResType     kEmbedHelpTextRB                 = 'emhR';
  13. const ResType     kFileHelpTextRB                 = 'sfhR';
  14. const ResType     kRemoveB                         = 'rmvB';
  15. const ResType     kEditAppFileRefB                 = 'eafB';
  16.  
  17.  
  18. // ---------------------------------------------------------------------------
  19. //        • CEditorWindow
  20. // ---------------------------------------------------------------------------
  21. CEditorWindow::CEditorWindow( SInt16 inFileRefNum, SInt16 inPreferenceRsrcID, SInt16 inResListRsrcID )
  22.     : StDialogHandler(200, NULL), mFileRefNum(inFileRefNum), mPreferenceRsrcID(inPreferenceRsrcID), mResListRsrcID(inResListRsrcID), mFlags(0), mStringListRsrcID(0), mMainTextRsrcID(0), mHelpTextRsrcID(0), mAppFileRefRsrcID(0)
  23.  
  24. {
  25.  
  26.     if( mPreferenceRsrcID == 0 ) {
  27.         SInt16** theIDHandle = (SInt16**) GetIndResource( 'paul', 1 );    //Get Resource ID for plugin preference
  28.         if (theIDHandle != NULL)
  29.             mPreferenceRsrcID = **theIDHandle;
  30.         else
  31.             mPreferenceRsrcID = 3500;
  32.     }
  33.  
  34. }
  35.  
  36. // ---------------------------------------------------------------------------
  37. //        • ~CEditorWindow
  38. // ---------------------------------------------------------------------------
  39. CEditorWindow::~CEditorWindow()
  40. {
  41. }
  42.  
  43.  
  44. // ---------------------------------------------------------------------------
  45. //        • DoEdit
  46. //
  47. //        Opens the editor window and handles all editing actions.  Returns
  48. //        a value indicating how the user finished the editing task
  49. //
  50. // ---------------------------------------------------------------------------
  51. SInt32    CEditorWindow::DoEdit()
  52. {
  53.     
  54.     SInt32            theResult = -1;
  55.     LWindow*        theDialog = GetDialog();
  56.  
  57.     this->LoadWindowFromFile();
  58.     
  59.     theDialog->Show();
  60.     
  61.     // Set active field
  62.     LEditField*    theField = (LEditField*) mDialog->FindPaneByID(kPanelTitleET);
  63.     SignalIf_(theField == nil);
  64.     mDialog->SetLatentSub(theField);
  65.  
  66.     
  67.     while (true) {
  68.         MessageT    hitMessage = DoDialog();
  69.         
  70.         if (hitMessage == msg_Cancel) {                                    // Cancel button
  71.             theResult = 1;
  72.             break;
  73.             
  74.         } else if (hitMessage == msg_OK) {                                // OK button
  75.             this->SaveWindowToFile();
  76.             theResult = 0;
  77.             break;
  78.             
  79.         } else if (hitMessage == kRemoveB) {                            // Remove button
  80.             theResult = 2;
  81.             break;
  82.         
  83.         } else if (hitMessage == kEditMainTextB) {                        // Edit main text
  84.                 DoEditText( mFileRefNum, mMainTextRsrcID  );
  85.                 
  86.         } else if (hitMessage == kEditHelpTextB) {                        // Edit help text
  87.         
  88.             if( mDialog->FindPaneByID(kEmbedHelpTextRB)->GetValue() )
  89.                 DoEditText( mFileRefNum, mHelpTextRsrcID  );
  90.             else
  91.                 DoEditFileRef( mFileRefNum, mHelpTextRsrcID );
  92.                 
  93.         } else if (hitMessage == kEditAppFileRefB) {                    // Edit application location
  94.             DoEditFileRef( mFileRefNum, mAppFileRefRsrcID );
  95.         
  96.         } else {                                                        // Idle time tasks
  97.         
  98.             if( mDialog->FindPaneByID(kEmbedHelpTextRB)->GetValue() )
  99.                 mDialog->FindPaneByID(kFirstHelpPicET)->Enable();
  100.             else
  101.                 mDialog->FindPaneByID(kFirstHelpPicET)->Disable();
  102.     
  103.         }
  104.     }
  105.     
  106.     return theResult;
  107. }
  108.  
  109.  
  110. // ---------------------------------------------------------------------------
  111. //        • SaveWindowToFile
  112. //
  113. //        Writes the contents of the window out to the plug-in's preference
  114. //        resource.
  115. //
  116. // ---------------------------------------------------------------------------
  117. void CEditorWindow::SaveWindowToFile()
  118. {
  119.     SInt16    savedResFile = CurResFile();
  120.     UseResFile( mFileRefNum );
  121.     
  122.     TRsrcHandle* theRsrcStream = new TRsrcHandle();
  123.     SignalIf_(theRsrcStream == nil);
  124.     
  125.     if( mStringListRsrcID == 0 )
  126.          mStringListRsrcID = GetUniqueIDForResType( mFileRefNum, 'STR#' );         
  127.  
  128.     theRsrcStream->AppendShort( 0 );    // Append Format
  129.  
  130.     // Help Text flag
  131.     LStdRadioButton* theRadioButton = (LStdRadioButton*) mDialog->FindPaneByID(kEmbedHelpTextRB);
  132.     SignalIf_(theRadioButton == nil);
  133.     if( theRadioButton->GetValue() )
  134.         mFlags &= ~kHelpTextInFile;
  135.     else
  136.         mFlags |= kHelpTextInFile;
  137.  
  138.  
  139.     theRsrcStream->AppendShort( mFlags );
  140.     theRsrcStream->AppendShort( mMainTextRsrcID );
  141.     theRsrcStream->AppendShort( mHelpTextRsrcID );
  142.  
  143.  
  144.     // First Help pict value
  145.     LEditField* theField = (LEditField*) mDialog->FindPaneByID(kFirstHelpPicET);
  146.     SignalIf_(theField == nil);
  147.     SInt16    theHelpFirstPictRsrcID = theField->GetValue();
  148.     theRsrcStream->AppendShort( theHelpFirstPictRsrcID );
  149.     
  150.     // Panel name
  151.     theField = (LEditField*) mDialog->FindPaneByID(kPanelTitleET);
  152.     SignalIf_(theField == nil);
  153.     Str255    theStr;
  154.     theField->GetDescriptor( theStr );
  155.     WriteStringListResourceIndex( mFileRefNum, theStr, mStringListRsrcID, 1 );
  156.     theRsrcStream->AppendShort( mStringListRsrcID );
  157.             
  158.     // Help window title string
  159.     UseResFile( savedResFile );
  160.     GetIndString( theStr, 233, 2 );
  161.     UseResFile( mFileRefNum );
  162.     
  163.     WriteStringListResourceIndex( mFileRefNum, theStr, mStringListRsrcID, 2 );            
  164.     
  165.             
  166.     // App File Ref
  167.     theRsrcStream->AppendShort( mAppFileRefRsrcID );
  168.     
  169.     
  170.     // Build Res list resource
  171.     ResetResListResource( mFileRefNum, mResListRsrcID );
  172.     AppendToResListResource( mFileRefNum, mResListRsrcID, 'sapr', mPreferenceRsrcID );
  173.     AppendToResListResource( mFileRefNum, mResListRsrcID, 'STR#', mStringListRsrcID );
  174.     
  175.     if( mFlags & kHelpTextInFile ) {
  176.         AppendToResListResource( mFileRefNum, mResListRsrcID, 'flrf', mHelpTextRsrcID );
  177.     } else {
  178.         AppendToResListResource( mFileRefNum, mResListRsrcID, 'TEXT', mHelpTextRsrcID );
  179.         AppendToResListResource( mFileRefNum, mResListRsrcID, 'styl', mHelpTextRsrcID );
  180.         AppendToResListResource( mFileRefNum, mResListRsrcID, 'PICT', theHelpFirstPictRsrcID );
  181.     }
  182.     
  183.     AppendToResListResource( mFileRefNum, mResListRsrcID, 'TEXT', mMainTextRsrcID );
  184.     AppendToResListResource( mFileRefNum, mResListRsrcID, 'styl', mMainTextRsrcID );
  185.  
  186.  
  187.     AppendToResListResource( mFileRefNum, mResListRsrcID, 'flrf', mAppFileRefRsrcID );
  188.  
  189.     theRsrcStream->Write( mFileRefNum, 'sapr', mPreferenceRsrcID );
  190.  
  191.             
  192.     delete theRsrcStream;
  193.     
  194.     UseResFile( savedResFile );
  195. }
  196.  
  197.  
  198. // ---------------------------------------------------------------------------
  199. //        • LoadWindowFromFile
  200. //
  201. //        Reads plug-in's preference resource and fills in fields of editor window.
  202. //        If the resource hasn't been created yet, then routine provides default
  203. //        values for the fields.
  204. //
  205. // ---------------------------------------------------------------------------
  206. void CEditorWindow::LoadWindowFromFile()
  207. {
  208.     
  209.     SInt16    savedResFile = CurResFile();
  210.     UseResFile( mFileRefNum );
  211.     
  212.     Handle         theRsrcHandle = Get1Resource( 'sapr', mPreferenceRsrcID );
  213.     
  214.     if( theRsrcHandle )
  215.     {
  216.         TRsrcHandle* theRsrcStream = new TRsrcHandle( theRsrcHandle );
  217.         SignalIf_(theRsrcStream == nil);
  218.     
  219.         if( theRsrcStream->ReadShort() == 0)
  220.         {
  221.         
  222.             mFlags                             = theRsrcStream->ReadShort();
  223.  
  224.             // Set Embedded Help Text Radio Button
  225.             LStdRadioButton* theRadioButton = (LStdRadioButton*) mDialog->FindPaneByID(kEmbedHelpTextRB);
  226.             SignalIf_(theRadioButton == nil);
  227.             theRadioButton->SetValue( (mFlags & kHelpTextInFile) != kHelpTextInFile );
  228.  
  229.             // Set File Help Text Radio Button
  230.             theRadioButton = (LStdRadioButton*) mDialog->FindPaneByID(kFileHelpTextRB);
  231.             SignalIf_(theRadioButton == nil);
  232.             theRadioButton->SetValue( (mFlags & kHelpTextInFile) == kHelpTextInFile );
  233.  
  234.             mMainTextRsrcID                    = theRsrcStream->ReadShort();
  235.             mHelpTextRsrcID                    = theRsrcStream->ReadShort();
  236.  
  237.             // Set First Help pict value
  238.             LEditField* theField = (LEditField*) mDialog->FindPaneByID(kFirstHelpPicET);
  239.             SignalIf_(theField == nil);
  240.             theField->SetValue( theRsrcStream->ReadShort() );
  241.             
  242.             // Set Panel name
  243.             theField = (LEditField*) mDialog->FindPaneByID(kPanelTitleET);
  244.             SignalIf_(theField == nil);
  245.             mStringListRsrcID = theRsrcStream->ReadShort(); 
  246.             Str255    thePanelTitleStr;
  247.             GetIndString( thePanelTitleStr, mStringListRsrcID, 1 );
  248.             theField->SetDescriptor( thePanelTitleStr );
  249.  
  250.             
  251.             // App File Ref
  252.             mAppFileRefRsrcID = theRsrcStream->ReadShort();
  253.             
  254.         }
  255.         
  256.         delete theRsrcStream;
  257.  
  258.     } else {
  259.         mFlags                        = 0;
  260.         mStringListRsrcID            = 0;
  261.         mMainTextRsrcID                = 0;
  262.         mHelpTextRsrcID                = 0;
  263.         mAppFileRefRsrcID            = 0;
  264.     }
  265.     
  266.     UseResFile( savedResFile );
  267. }
  268.  
  269.  
  270.  
  271.